package com.musicdaze.utils;

/**
 * This class represents a wrapper for an object that has a current and original
 * value. It is also resetable.
 * @author mfujihara
 * 
 * @param <T>
 */
public class Value<T> implements Resettable {
  /** params */
  private T original;
  private T current;

  /**
   * Constructs a Value with original as the start value.
   * @param original the start value
   */
  public Value(T original) {
    this.original = original;
    this.current = original;
  }

  /**
   * Sets the current value
   * @param value the value to set as current
   */
  public void setValue(T value) {
    this.current = value;
  }

  /**
   * Gets the current value
   * @return the current value
   */
  public T getCurrentValue() {
    return this.current;
  }

  /** {@inheritDoc} */
  public void reset() {
    this.current = this.original;
  }

  /** {@inheritDoc} */
  @Override
  public boolean equals(Object o) {
    if (o instanceof Value) {
      Value v = (Value) o;
      return v.current.equals(this.current) && v.original.equals(this.original);
    }
    return false;
  }

  /** {@inheritDoc} */
  @Override
  public int hashCode() {
    return current.hashCode() + original.hashCode();
  }
}
